import java.util.*;

public class BiteDay42 {
    public int countKeyChanges(String s) {
        char[] arr = s.toCharArray();
        int ret = 0;
        for(int i = 1; i < arr.length; i++){
            if(arr[i] == arr[i-1] || arr[i]==arr[i-1]+32 || arr[i]==arr[i-1]-32){

            }else{
                ret++;
            }
        }
        return ret;
    }

    static class Pair{
        public int key;
        public int value;

        public Pair(int key, int value) {
            this.key = key;
            this.value = value;
        }
    }
    public  static int maximumLength(int[] nums) {
        Arrays.sort(nums);
        HashMap<Integer, Integer> hashMap = new HashMap<>();
        List<Pair> list = new ArrayList<>();
        for(int e : nums){
            if(hashMap.get(e) == null){
                list.add(new Pair(e,1));
            }
            hashMap.put(e, hashMap.getOrDefault(e, 0)+1);
        }

//        for(Pair e : list){
//            int key = e.key;
//            int value = e.value;
//            System.out.print("<"+key+","+value+">");
//        }

//        for(Map.Entry<Integer, Integer> e : hashMap.entrySet()){
//            System.out.print("<"+e.getKey()+","+e.getValue()+">");
//        }

        int n = list.size();
        for(int i = n - 1; i >= 0; i--){
            int next = list.get(i).key * list.get(i).key;
            if(hashMap.get(list.get(i).key) >= 2 && hashMap.get(next) != null){

                int j = 0;
                for(j = i+1; j < n; j++){
                    if(list.get(j).key==next){

                        list.get(i).value = list.get(j).value + 1;
                        break;
                    }
                }

            }else{
                list.get(i).value = 1;
            }
        }
        if(list.get(0).key==1){
            list.get(0).value = (hashMap.get(1)+1)/2;
        }
        int ret = 0;
        for(Pair e : list){
            int value = e.value;
            ret = Math.max(ret, value);
        }
        return ret * 2 - 1;
    }

    public static void main1(String[] args) {
        int[] arr = new int[]{1,1,1,1,1,1};
        maximumLength(arr);
    }


    public static void main2(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String s = sc.nextLine();
            char arr[] = s.toCharArray();
            StringBuilder ans = new StringBuilder();
            for(char e : arr){
                if(e >= '0' && e <= '9'){
                    ans.append(e);
                }
            }
            System.out.println(ans);
        }
    }

    private static boolean check(char[][] arr, int x, int y){
        if(x >= 0 && x < 10
        && y >=0 && y < 10
        && arr[x][y] == '.'){
            return true;
        }
        return false;
    }

    private static int dfs(char[][] arr, int x, int y, int step){
        int[] ans = new int[]{Integer.MAX_VALUE,Integer.MAX_VALUE,Integer.MAX_VALUE,Integer.MAX_VALUE};
        arr[x][y] = '#';
        if(x == 9 && y == 8){
            return step;
        }
        //上
        if(check(arr, x-1, y)){
            ans[0] = dfs(arr, x-1, y, step+1);
            arr[x-1][y] = '.';
        }
        //下
        if(check(arr, x+1, y)){
            ans[1] = dfs(arr, x+1, y, step+1);
            arr[x+1][y] = '.';
        }
        //左
        if(check(arr, x, y-1)){
            ans[2] = dfs(arr, x, y-1, step+1);
            arr[x][y-1] = '.';
        }
        //右
        if(check(arr, x, y+1)){
            ans[3] = dfs(arr, x, y+1, step+1);
            arr[x][y+1] = '.';
        }
        Arrays.sort(ans);
        return ans[0];
    }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            char[][] arr = new char[10][10];
            for(int i = 0; i < 10; i++){
                String s = sc.next();
                arr[i] = s.toCharArray();
            }
            int ret = dfs(arr, 0, 1, 0);
            System.out.println(ret);
        }
    }
}
